 package com.es.main;
 
 import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.xwork.ActionSupport;
 
 @SuppressWarnings("serial")
public class LoginAction extends ActionSupport
   implements ServletRequestAware
 {
   HttpServletRequest request;
 
   public String execute()
     throws Exception
   {
     this.request.setCharacterEncoding("utf-8");
     HttpSession session = this.request.getSession(true);
     session.setMaxInactiveInterval(7200);
 
     LoginBiz biz = new LoginBiz();
     LoginUserBeen loginuser = new LoginUserBeen();
     String loginName = this.request.getParameter("loginName");
     String password = this.request.getParameter("password");
     if (password == null) {
       password = "";
     }
     ArrayList<String> queryParm = new ArrayList<String>();
     queryParm.add(loginName);
     queryParm.add(password);     
     try {
		loginuser = biz.login(queryParm);
	} catch (Exception e) {
		System.out.print(e.getMessage());
	}
     
     String message = "";
     if (loginuser == null||loginuser.getLoginId()==null) {
       message = "用户名不存在,或密码错误，请重新尝试";
       this.request.setAttribute("message", message);
       return "login";
     } 
     session.setAttribute("loginuser", loginuser);
     return "success";
   }
 
   public void setServletRequest(HttpServletRequest request) {
     this.request = request;
   }
 }
